import React, { useEffect, useMemo, useState } from 'react'
import currentEnv from "../../../configure/currentEnv"
import {View, Button,Image,Swiper,SwiperItem} from '@tarojs/components'
import Taro, { useDidShow } from '@tarojs/taro'
import './index.less'

export default function PayStatus() {
  const [info,setInfo] = useState({})
  const [isApp,setIsApp] = useState(false)
  const [swiperList,setSwiperList] = useState([])
  useEffect(()=>{
    const {params} = Taro.getCurrentInstance().router
    if(params.channel && params.channel.includes('app')){
      setIsApp(true)
    }
    Taro.showLoading({title:'加载中...'})
    Taro.$get(`/act/orders/v3/${params.id}`,'','1').then(res=>{
      if(res.code == '1'){
        setInfo(res.content)
      }else{
        Taro.showToast({
          title: res.message,
          icon:'none'
        })
      }
    })
    // Taro.$get('/act/index/selectAdvertisingListByAlias/pay-result').then(res=>{
    //   setSwiperList(res.content.advertisesList || [1])
    // })
  },[])
  
  function handleToBanner(e){
    if(process.env.TARO_ENV == 'h5'){
      if(e.url.includes('http')){
        location.href = e.url
      }else{
        Taro.navigateTo({
          url:e.url
        })
      }
      return;
    }
    if(e.url.includes('http')){
      Taro.navigateTo({
        url:`/pages/fineEngine/webView?url=${e.url}`
      })
      return;
    }
    Taro.navigateTo({
      url:e.url
    })
  }

  return (
    <View className="pay-status">
      <View className="box-flex">
        <Image className="status-img" src='' mode="widthFix"></Image>
        <View className='h1'>{info.orderType=='Ticket'?'购票成功':'购买成功'}</View>
      </View>
      {/* <View className='h2'>{info.topicTitle} ({info.seats?.length}张)</View> */}
      <View className='p'>付款已经完成</View>
      <View className="box-flex status-button">
        <Button className="button" onClick={()=>{
          Taro.reLaunch({
            url:currentEnv.project=='yingjing'?'/pages/index/index':'/pages/movie/index'
          })
        }}>返回首页</Button>
        {isApp?<Button open-type="launchApp" app-parameter="id" binderror="launchAppError">打开APP</Button>:<Button className='button active' onClick={()=>{
          Taro.redirectTo({
            url:'/orderSubPack/order-list/index'
          })
        }}>查看订单</Button>}
      </View>
      {swiperList.length?<>
        {swiperList.length > 1?
        <View className="home-swiper">
          <Swiper className="swiper-main" autoplay={true} interval={3000} duration={1000}>
            {swiperList.map(item=>{
              return <SwiperItem key={item.id} onClick={()=>{handleToBanner(item)}}>
              <Image className="image" src={item.imageUrl} mode="aspectFill"></Image>
            </SwiperItem>
            })}
          </Swiper>
        </View>:
        <View style="margin: 16rpx 32rpx;"><Image className="image" src={swiperList[0].imageUrl} mode="aspectFill"></Image></View>}
      </>:null}
    </View>
  )
}
